<?php
class Vote extends TagsAbstract {
	/**
	 * 是否是封闭的标签
	 * @var unknown_type
	 */
	static $TAG_CLOSED = false;
	
	public $config = array();
	
	public function __construct(){

	}
	public function getTagStatus(){
		return self::$TAG_CLOSED;
	}
	/**
	 * 返回模板文件路径
	 */
	public function getTemplateFile($tpl = "") {
		//返回需要渲染的模板
		$file = $this->attr ['style'];
	if(!empty($tpl)){
			$file = $tpl;
		}
		return dirname(__FILE__).'/vote/'.$file.'.html';
	}
	
	/**
	 * 设置使用哪个Widget,暂时无用。。
	 */
	public function setWidget() {
		return 'test';
	}
	
	/**
	 * 这里返回的是模板中需要渲染的变量
	 */
	public function replace($checkCache) {
		$vid = intval($this->attr['id']);
		//投票详情、投票选项、投票人
		$vote = M('vote')->where('id=' . $vid)->limit(1)->findAll();
		$var['vote'] = $vote[0];
		$var['opt']  = M('vote_opt')->where('vote_id=' . $vid)->order('id ASC')->findAll();
		$var['user'] = M('vote_user')->where('vote_id=' . $vid)->order('cTime DESC')->findAll();
		
		$has_vote = 0; //当前用户是否已投票
		foreach($var['user'] as $v) {
			if($_SESSION['mid'] == $v['uid'] && !empty($v['opts'])) {
				$has_vote = 1;
			}
		}
		$var['has_vote'] = $has_vote;

		$var['attr'] = $this->attr;
		return $var;
	}
}
?>